package com.levi.functionalinterface;

import com.levi.lambda.Student;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Predicate;

/**
 * @author shentong
 * @date 2022/1/10 9:56 PM
 * @description  Predicate接口主要用于判断
 */

public class MyPredicateDemo {

    public static List<Student> filter(List<Student> studentList, Predicate<Student> predicate){
        List<Student> list = new ArrayList<>();
        for (Student student : studentList) {
            //test方法需要具体实现
            if (predicate.test(student)){
                list.add(student);
            }
        }
        return list;
    }


    public static void main(String[] args) {
        List<Student> studentList = new ArrayList<Student>(){{
            add(new Student(1, "张三", "男"));
            add(new Student(2, "李四", "男"));
            add(new Student(3, "王五", "女"));
        }};
        List<Student> filter = filter(studentList, (student -> student.getSex().equals("女")));
        filter.forEach(System.out::println);
    }
}
